<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopDispatchTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_dispatch', ['comment' => '发货模板', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('name', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '模板名称'])
            ->addColumn(Column::enum('type', ['express'])->setDefault('express')->setComment('发货方式:express=快递物流'))
            ->addColumn(Column::enum('status', ['normal', 'disabled'])->setDefault('normal')->setComment('状态:normal=正常,disabled=禁用'))
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();


        $table = $this->table('shop_dispatch_express', ['comment' => '运费模板', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('dispatch_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '配送模板'])
            ->addColumn(Column::enum('type', ['number', 'weight'])->setDefault('number')->setComment('计费方式:number=件数,weight=重量'))
            ->addColumn('first_num', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '首(重/件)数'])
            ->addColumn('first_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '首(重/件)'])
            ->addColumn('additional_num', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '续(重/件)数'])
            ->addColumn('additional_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '续(重/件)'])
            ->addColumn('province_ids', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '省份'])
            ->addColumn('city_ids', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '城市'])
            ->addColumn('district_ids', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '地区'])
            ->addColumn('weigh', 'integer', ['limit'  =>  8, 'default' => 0, 'comment' => '权重'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_dispatch');
        $table->drop();

        $table = $this->table('shop_dispatch_express');
        $table->drop();
    }
}
